package com.ficus.road.maintain.core.model.zh.xlj;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.apache.commons.lang3.ObjectUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author xiawen yang
 * @date 2022/6/27 上午11:33
 */
@Data
public class XljLatestInfoZH {
    private String unid;

    private String xljName;

    @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
    private Date updatetime;
    // 封交状态
    private Integer isClosed;
    // 排水状态
    private Integer isPumping;
    // 值守状态
    private Integer guardStatus;
    // 积水值
    private Integer value;
    //泵站状态
    private String state;
    // 摄像机状态数组
    private List<CameraStatusZH> XLJ_CAM_STATUS;

    public XljLatestInfo convert2XljLatestInfo(XljLatestInfoZH zh, Date date) {
        return XljLatestInfo.builder()
                .xljId(zh.getUnid())
                .closeStatus(zh.getIsClosed())
                .pumpingStatus(zh.getIsPumping())
                .guardStatus(zh.getGuardStatus())
                .updateTime(zh.getUpdatetime())
                .value(zh.getValue())
                .state(zh.getState())
                .cameraList(ObjectUtils.isEmpty(zh.getXLJ_CAM_STATUS()) ? new ArrayList<>() : zh.getXLJ_CAM_STATUS().stream().map(item -> item.convert2Camera(item)).collect(Collectors.toList()))
                .syncTime(date)
                .build();
    }

    @Data
    public static class CameraStatusZH {
        private String CAM_ID;

        private String CAMERA_STATUS;
        @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
        private Date UPDATE_TIME;

        public XljBasicInfoZH.Camera convert2Camera(XljLatestInfoZH.CameraStatusZH zh) {
            return XljBasicInfoZH.Camera.builder()
                    .cameraId(zh.getCAM_ID())
                    .cameraStatus(zh.getCAMERA_STATUS())
                    .updateTime(zh.getUPDATE_TIME())
                    .build();
        }
    }
}
